import PyPDF2

# reader = PyPDF2.PdfFileReader('test.pdf')
# page = reader.getPage(0)
# print(page.extractText())

reader = PyPDF2.PdfFileReader('test.pdf')
page = reader.getPage(0)
page.rotateClockwise(90)
writer = PyPDF2.PdfFileWriter()
writer.addPage(page)
with open('test-rotated.pdf', 'wb') as file:
    writer.write(file)


# with open('test.pdf', 'rb') as file:
#     reader = PyPDF2.PdfFileReader(file)
#     writer = PyPDF2.PdfFileWriter()
#     for page_num in range(reader.numPages):
#         writer.addPage(reader.getPage(page_num))
#     writer.encrypt('foobared')
#     with open('test-encrypted.pdf', 'wb') as file2:
#         writer.write(file2)

# from io import StringIO
#
# from pdfminer.converter import PDFPageAggregator
# from pdfminer.layout import LAParams, LTTextBoxHorizontal
# from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
# from pdfminer.pdfpage import PDFPage
# from pdfminer.pdfparser import PDFParser, PDFDocument
#
#
# def pdf_to_text(path):
#     buffer = StringIO()
#     parser = PDFParser(path)
#     document = PDFDocument(parser)
#     if document.is_extractable:
#         manager = PDFResourceManager()
#         device = PDFPageAggregator(manager, laparams=LAParams())
#         interpreter = PDFPageInterpreter(manager, device)
#         for page in PDFPage.create_pages(document):
#             interpreter.process_page(page)
#             layout = device.get_result()
#             for content in layout:
#                 if isinstance(content, LTTextBoxHorizontal):
#                     buffer.write(content.get_text())
#     return buffer.getvalue()
#
#
# pdf_to_text('Zen-Of-Python.pdf')
